#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int M = 1e5 + 5;
const int K = 1e3 + 5;
int t,n,m,l,sd,d[M],a[M],v[M],p1,ans1,g[N],ans2;
pair<int,int> pir[M];
bool p[N],car[M];
void solve() {
    cin >> n >> m >> l >> sd;
    for (int i = 1;i <= n;i++) cin >> d[i] >> v[i] >> a[i];
    for (int i = 1;i <= N;i++) p[i] = false;
    for (int i = 1;i <= M;i++) car[i] = false;
    for (int i = 1;i <= m;i++) {
        cin >> p1;
        p[p1] = true;
    }
    for (int i = 1;i <= n;i++) {
        if (a[i] == 0) {
            if (v[i] > sd) {
                pir[i].first = d[i];
                pir[i].second = l;
            } else {
                pir[i].first = l+1;
                pir[i].second = -1;
            }
        } else if (a[i] > 0) {
            if (v[i] > sd) {
                pir[i].first = d[i];
                pir[i].second = l;
            } else if (v[i] <= sd) {
                int kk = d[i] + ((sd*sd-v[i]*v[i])/(2*a[i]))+1;
                if (kk <= l) {
                    pir[i].first = kk;
                    pir[i].second = l;
                } else {
                    pir[i].first = l+1;
                    pir[i].second = -1;
                }
            }
        } else if (a[i] < 0) {
            if (v[i] <= sd) {
                pir[i].first = l+1;
                pir[i].second = -1;
            } else {
                int kk = d[i] + ((sd*sd-v[i]*v[i])/(2*a[i]))-1;
                if (kk <= l) {
                    pir[i].first = d[i];
                    pir[i].second = kk;
                } else {
                    pir[i].first = d[i];
                    pir[i].second = l;
                }
            }
        }
    }
    for (int i = 1;i <= n;i++) {
        if (pir[i].first <= pir[i].second) {
            for (int j = pir[i].first;j <= pir[i].second;j++) {
                if (p[j] && !car[i]) {
                    g[j] ++;
                    ans1++;
                    car[i] = true;
                }
            }
        }
    }
    cout << ans1 << " ";


}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> t;
    while (t--) solve();
    return 0;
}
